package com.qk.controller;

import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    //查询活动列表
    @GetMapping
    public Result list(Integer  channel, Integer  type, Integer status,
                       @RequestParam(defaultValue = "1")Integer page,
                       @RequestParam (defaultValue = "10")Integer pageSize){
        log.info("查询活动列表");
        return Result.success(activityService.list(channel, type, status, page, pageSize));
    }

    //根据ID删除活动
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除活动");
        activityService.deleteById(id);
        return Result.success();
    }

    //添加活动
    @PostMapping
    public Result add(@RequestBody Activity activity){
        log.info("添加活动");
        activityService.add(activity);
        return Result.success();
    }

    //根据ID查询活动
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("查询活动id:{}", id);
        return Result.success(activityService.getById(id));
    }

    //更新活动
    @PutMapping
    public Result update(@RequestBody Activity activity){
        log.info("更新活动");
        activityService.update(activity);
        return Result.success();
    }

    //查询指定类型活动
    @GetMapping("type/{type}")
    public Result listByType(@PathVariable Integer type){
        log.info("查询指定类型活动");
        //调用Mapper方法进行查询
        List<Activity> activities = activityService.listByType(type);
        return Result.success(activities);
    }
}
